<?php
$page_title = 'eTAT: Create Survey';
$style = 'survey';
$script = 'survey';
require_once '../controller.php';
if(isset($params->sid)) {
	$s = new Survey($params->sid);
	$header_text = $s->survey_name;
} else {
	$header_text = 'New Survey';
}
if(isset($_POST['submit_survey']) || isset($_POST['save_survey'])) {
	$data = (object) array (
		'survey_name' => addslashes($_POST['name']),
		'survey_title' => addslashes($_POST['title']),
		'welcome_message' => addslashes($_POST['welcome_message']),
		'confirmation_message' => addslashes($_POST['confirmation_message']),
		'email_subject'=>addslashes($_POST['title']),
		'email_message'=>addslashes($_POST['welcome_message']),
		'date_created'=> time(),
		'last_modified'=> time()
	);
	if(isset($params->sid)) {
		$s->updateSurvey($data);
	} else {
		$instructor->createSurvey($data);
	}
	if(isset($_POST['submit_survey'])) {
		redirect("survey/content.php?sid=$s->id");
	} else {
		redirect('survey/');
	}
}
require_once '../header.php';
print '<h1>'.anchor('survey/','Surveys',array('noselect'=>false)).' > '.$header_text.'</h1>';
?>
<p>Please fill in the following fields:</p>
<br />
<div id='create-survey'>
<?php
$form = new Form('survey');
$form->textInput('name','Survey Name',array('required'=>true,'value'=>stripslashes($s->survey_name)));
$form->textInput('title','Survey Title',array('required'=>true,'value'=>stripslashes($s->survey_title)));
$form->textArea('welcome_message','Welcome Message',2,30,array('value'=>stripslashes($s->welcome_message)));
$form->textArea('confirmation_message','Confirmation Message',2,30,array('value'=>stripslashes($s->confirmation_message)));
$form->button('cancel','Cancel',array('type'=>'button','onclick'=>'window.location="http://'.HOST.'/survey/"'),false);
$form->button('save_survey','Save & Close',array('class'=>'right'),false);
$form->button('submit_survey','Edit Content',array('class'=>'right'),false);
print $form->build();
?>
</div>
<div class='clear'></div>
<?php require_once '../footer.php'; ?>